package ControlLayer;
import java.util.ArrayList;
import java.util.Collection;
import ModelLayer.*;



/**
 * Controller class for the address book
 * 
 * @author (Martin x 2) 
 * @version (2011.04.12)
 * 
 */
public class AddressBookController
{
    private AddressBook addressBook;
    private static AddressBookController instance;
    
    //Address container is to be passed as parameter from the main controller
    private AddressBookController() {
        addressBook = AddressBook.getInstance();
    }
    
    public static AddressBookController getInstance() {
        if(instance == null) {
            instance = new AddressBookController();
        }
        
        return instance;
    }
    
    //Dummy implementation: after implementing the model layer 
    //objects of class Person are to be returned, not String
    public ArrayList<Person> search(String query)
    {
        return addressBook.search(query);
    }
    
    public Person getPerson(int id)
    {
        Person person = addressBook.getPerson(id);
        return person;
    }
        
    public int createPerson(String name, String address, int zipCode, String city, int phone)
    {   
       Person person = new Person(name, address, zipCode, city, phone);
       int id = addressBook.addPerson(person);
       return id;
    }
    
    public boolean removePerson(Person person)
    {
        return addressBook.removePerson(person);
    }
    
    public void editAddress(Person person, String address)
    {
        person.setAddress(address);
    }
    
    public void editName(Person person, String name)
    {
        person.setName(name);
    }
    
    public void editZipCode(Person person, int zipCode)
    {
        person.setZipCode(zipCode);
    }
    
    public void editCity(Person person, String city)
    {
        person.setCity(city);
    }
    
    public void editPhone(Person person, int phone)
    {
        person.setPhone(phone);
    }
    
    public ArrayList<Person>getAllPersons() {
        return AddressBook.getInstance().getAllPersons();
    }
}
